import java.util.Deque;
import java.util.LinkedList;

class Solution1 {
    public String removeDuplicates(String s) {
        Deque<Character> q = new LinkedList<>();
        char ch;
        for(int i=0;i<s.length();i++){
            ch = s.charAt(i);
            if(q.isEmpty() || q.peek() != ch ){
                q.push(ch);
            }else{
                q.pop();
            }
        }
        StringBuilder sb = new StringBuilder();
        while(!q.isEmpty()){
            sb.append(q.pop());
        }
        return sb.reverse().toString();

    }
}